﻿using SYJ.BLL;
using SYJ.IBLL;
using SYJ.Model;
using SYJ.Model.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using SYJ.Common.web;
using System.Threading;
using Dapper;

namespace SYJ.Logic.Controllers.admin
{
   public class SysRoleMgrController:BaseController
    {
       private ISysRoleBLL bll = new SysRoleBLL();
       public ActionResult Index() {

           return View();
       }
       public ActionResult GetSysRoleList(QueryModel query, string title)
       {
           long count=0;
          
           if (!string.IsNullOrEmpty(title)) {
               query.SqlWhere = " and title like ?title ";
               query.Param.Add("title", "%" + title + "%");
           }
           List<SysRole> list = bll.GetPage(query,out count);
           var respose = JsonLayuiGridData<SysRole>.Create(query, list, count, "");
           return Json(respose, JsonRequestBehavior.AllowGet);
       }
       [HttpGet]
       public ActionResult AddOrUp(int? id)
       {
           SysRole role = new SysRole();
           if (id != null) {
               role = bll.GetModel(Convert.ToInt32(id));
           }
           return View(role);
       }
       [HttpPost]
       public ActionResult AddOrUp(SysRole model)
       {
           if (model.id > 0)
           {
               return Json(bll.Update(model), JsonRequestBehavior.AllowGet);
           }
           else
           {
               return Json(bll.Insert(model), JsonRequestBehavior.AllowGet);
           }
       }

       public ActionResult Delete(int id)
       {
           bool delete = bll.Delete(new SysRole() { id=id});
           return Json(delete, JsonRequestBehavior.AllowGet);
       }
    }
}
